<template>
  <div class="my-container">
    <van-cell-group class="my-info" v-if="user">
      <van-cell
        center
        class="my-info-item"
        :border="false"
      >
        <van-image
          slot="icon"
          width="50"
          height="50"
          class="avatar"
          round
          fit="cover"
          :src="currentUser.photo"
        />
        <div slot="title" style="color: #fff">{{currentUser.name}}</div>
        <van-button
         size="small"
         style="height: 20px"
         round
         to='/user'
          >编辑资料</van-button
        >
      </van-cell>
      <van-grid :border="false" class="data-info">
        <van-grid-item class="data-info-item">
          <div slot="text" class="text-wrap">
            <div class="span">{{currentUser.art_count}}</div>
            <div class="text">头条</div>
          </div>
        </van-grid-item>
        <van-grid-item class="data-info-item">
          <div slot="text" class="text-wrap">
            <div class="span">{{currentUser.fans_count}}</div>
            <div class="text">关注</div>
          </div>
        </van-grid-item>
        <van-grid-item class="data-info-item">
          <div slot="text" class="text-wrap">
            <div class="span">{{currentUser.follow_count}}</div>
            <div class="text">粉丝</div>
          </div>
        </van-grid-item>
        <van-grid-item class="data-info-item">
          <div slot="text" class="text-wrap">
            <div class="span">{{currentUser.like_count}}</div>
            <div class="text">获赞</div>
          </div>
        </van-grid-item>
      </van-grid>
    </van-cell-group>
    <div class="no-login" v-else>
      <div class="no-login-content">
        <img
          src="./手机.png"
          class="no-login-mobile"
          @click="$router.push({
            path:'/login',
            query:{
              redirect:'/my'
            }
          })"
        />
        <div class="loginOReg">登录/注册</div>
      </div>
    </div>
    <van-grid class="nav-grid" :column-num="2">
      <van-grid-item
        icon-prefix="toutiao"
        icon="shoucang"
        class="nav-grid-item"
        text="查看"
      />
      <van-grid-item
        icon-prefix="toutiao"
        icon="lishi"
        text="历史"
        class="nav-grid-item"
      />
    </van-grid>
    <van-cell title="消息通知" is-link to="/" />
    <van-cell title="小智同学" class="bt-bottom" is-link to="/userChat" />
    <van-cell title="退出登录" class="logExit" v-if="user" @click="onLayOut" />
  </div>
</template>

<script>
import { userMessage } from '@/api/user'
import { mapState } from 'vuex'
export default {
  name: 'MyIndex',
  components: {},
  props: {},
  data () {
    return {
      currentUser: {}
    }
  },
  computed: {
    ...mapState(['user'])
  },
  watch: {},
  created () {},
  mounted () {
    this.getUserMes()
  },
  methods: {
    // 退出登录
    onLayOut () {
      // 提示用户退出登录
      this.$dialog.confirm({
        title: '退出登录',
        message: '您确定退出登录么'
      })
        .then(() => {
          // 确认 清除用户登录状态
          this.$store.commit('setUser', null)
        })
        .catch(() => {
          // on cancel
        })
    },
    // 获取用户信息
    async getUserMes () {
      try {
        const { data } = await userMessage()
        this.currentUser = data.data
      } catch (error) {
        console.log('error', error)
      }
    }
  }
}
</script>

<style scoped lang="less">
.my-container {
  .my-info {
    background: url("./banner.png") no-repeat;
    background-size: cover;
    color: #fff;
    .my-info-item {
      box-sizing: border-box;
      height: 115px;
      padding-top: 38px;
      padding-bottom: 11px;
    }
    .avatar {
      box-sizing: border-box;
      width: 66px;
      height: 66px;
      border: 1px solid #fff;
      margin-right: 11px;
    }
  }
  .no-login {
    background: url("./banner.png") no-repeat;
    background-size: cover;
    height: 180px;
    .no-login-content {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      .no-login-mobile {
        height: 66px;
        width: 66px;
        margin-top: 44px;
      }
      .loginOReg {
        font-size: 18px;
        color: #fff;
        margin-top: 5px;
      }
    }
  }
  .nav-grid {
    .nav-grid-item {
      height: 70px;
      /deep/.toutiao-shoucang {
        font-size: 22px;
        color: #eb5253;
      }
      /deep/.toutiao-lishi {
        font-size: 22px;
        color: #eb5253;
      }
    }
  }
  .text-wrap {
    display: flex;
    font-size: 17px;
    flex-direction: column;
    justify-self: center;
    align-items: center;
  }
  .van-cell {
    background: unset;
  }
  /deep/.van-grid-item__content {
    background: unset;
  }
  .logExit {
    text-align: center;
    color: #d86262;
    font-size: 18px;
  }
  .bt-bottom {
    margin-bottom: 4px;
  }
}
.data-info {
  .data-info-item {
    height: 65px;
  }
}
</style>
